package org.example.spring.carsalemanagementsystem.controller;

import lombok.RequiredArgsConstructor;
import org.example.spring.carsalemanagementsystem.entity.Accessory;
import org.example.spring.carsalemanagementsystem.service.AccessoryService;
import org.example.spring.carsalemanagementsystem.utils.Result;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/accessory")
@RequiredArgsConstructor
public class AccessoryController {
    private final AccessoryService accessoryService;
    @GetMapping("/findList")
    public Result findList(String carid) {
        List<Accessory> accessories = accessoryService.selectByCarId(carid);
        return Result.success().put(accessories);
    }
    @PostMapping("/insert")
    public Result insert(@RequestBody Accessory accessory) {
        accessoryService.insertOne(accessory);
        return Result.success();
    }
    @PostMapping("/deleteBatch")
    public Result delete(@RequestBody Map<String, Object> parameter) {
        List<String> ids = (List<String>) parameter.get("ids");
        accessoryService.deleteBatch(ids);
        return Result.success();
    }
}
